// routes/purchaseOrderRoutes.js
const express = require('express');
const router = express.Router();
const controller = require('../controllers/purchaseOrderController');

/**
 * @swagger
 * tags:
 *   name: PurchaseOrder
 *   description: 采购单管理接口
 */


/**
 * @swagger
 * /api/purchase-order:
 *   get:
 *     summary: 获取全部采购单
 *     tags: [PurchaseOrder]
 *     responses:
 *       200:
 *         description: 返回采购单列表
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                 data:
 *                   type: array
 */
router.get('/', controller.getAll);

/**
 * @swagger
 * /api/purchase-order/{id}:
 *   get:
 *     summary: 根据ID获取采购单
 *     tags: [PurchaseOrder]
 *     parameters:
 *       - name: id
 *         in: path
 *         required: true
 *         description: 采购单ID
 *         schema:
 *           type: integer
 *     responses:
 *       200:
 *         description: 返回单条采购单数据
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *       404:
 *         description: 未找到该采购单
 */
router.get('/:id', controller.getById);

/**
 * @swagger
 * /api/purchase-order:
 *   post:
 *     summary: 创建采购单
 *     tags: [PurchaseOrder]
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             required:
 *               - name
 *             properties:
 *               name:
 *                 type: string
 *                 description: 采购单名称
 *               numbering:
 *                 type: string
 *                 description: 编号
 *               purchaser:
 *                 type: integer
 *                 description: 采购人编号
 *               project:
 *                 type: integer
 *                 description: 项目编号
 *               total_cost:
 *                 type: number
 *                 format: decimal
 *                 description: 总花费
 *     responses:
 *       200:
 *         description: 创建成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                 message:
 *                   type: string
 *                 data:
 *                   type: object
 *                   properties:
 *                     id:
 *                       type: integer
 */
router.post('/', controller.create);

/**
 * @swagger
 * /api/purchase-order/{id}:
 *   put:
 *     summary: 更新采购单
 *     tags: [PurchaseOrder]
 *     parameters:
 *       - name: id
 *         in: path
 *         required: true
 *         description: 采购单ID
 *         schema:
 *           type: integer
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               name:
 *                 type: string
 *               numbering:
 *                 type: string
 *               purchaser:
 *                 type: integer
 *               project:
 *                 type: integer
 *               total_cost:
 *                 type: number
 *               status:
 *                 type: integer
 *     responses:
 *       200:
 *         description: 更新成功
 *       404:
 *         description: 未找到该采购单
 */
router.put('/:id', controller.update);

/**
 * @swagger
 * /api/purchase-order/{id}:
 *   delete:
 *     summary: 删除采购单（逻辑删除）
 *     tags: [PurchaseOrder]
 *     parameters:
 *       - name: id
 *         in: path
 *         required: true
 *         description: 采购单ID
 *         schema:
 *           type: integer
 *     responses:
 *       200:
 *         description: 删除成功
 *       404:
 *         description: 未找到该采购单
 */
router.delete('/:id', controller.delete);

module.exports = router;
